<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>QJoysticks: Introduction</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="icon.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">QJoysticks
   </div>
   <div id="projectbrief">A simple way to use joysticks with your Qt application</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li class="current"><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Introduction </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <a class="el" href="class_q_joysticks.html" title="Manages the input systems and communicates them with the application. ">QJoysticks</a> library allows your Qt application to read input from both real joysticks/gamepads (using SDL) and a virtual joystick (using the keyboard).</p>
<p>SDL binaries and headers for Windows and OS X are already included in this library. Linux uses will need to install libsdl2-dev using the package manager of their distro of choice.</p>
<h2>Integrating <a class="el" href="class_q_joysticks.html" title="Manages the input systems and communicates them with the application. ">QJoysticks</a> with your projects</h2>
<ol type="1">
<li>Copy this folder in your "3rd-party" folder.</li>
<li>Include the <a class="el" href="class_q_joysticks.html" title="Manages the input systems and communicates them with the application. ">QJoysticks</a> project include (<em>pri</em>) file using the include() function.</li>
<li>That's all! Check the example project as a reference for your project.</li>
</ol>
<h2>QML compatibility</h2>
<p>This library can be used from QML, just register it as a context property when initializing your QML engine (check the example project for more information).</p>
<h2>WTFs Section</h2>
<h3>1. What are the joystick IDs and how are they assigned?</h3>
<p>Each joystick has an numerical ID, which is used by the library and you to access joystick information. The ID is assigned based on the order in which a joystick was attached. Joystick IDs are always congruent to the lists returned by the following functions:</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;QStringList joystickNames = QJoysticks::getInstance()-&gt;deviceNames();</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;QList&lt;QJoystickDevice*&gt; joysticks = QJoysticks::getInstance()-&gt;inputDevices();</div></div><!-- fragment --><p><b>NOTE:</b> The virtual joystick will always be the last joystick to be registered, in other words, it will always have the greatest numerical ID.</p>
<h3>2. What is the virtual joystick?</h3>
<p>The virtual joystick uses your computer keyboard to generate axis, button and POV events. The keyboard mappings are:</p>
<table class="doxtable">
<tr>
<th>Keyboard Keys </th><th>Joystick Mappings  </th></tr>
<tr>
<td>W,A,S,D </td><td>Left Stick </td></tr>
<tr>
<td>I,J,K,L </td><td>Right Stick </td></tr>
<tr>
<td>Arrow Keys </td><td>POV hat </td></tr>
<tr>
<td>Q,E </td><td>Left Trigger </td></tr>
<tr>
<td>U,O </td><td>Right Trigger </td></tr>
<tr>
<td>0,1,2,3,4,5,6,7,8,9 </td><td>Joystick Buttons </td></tr>
</table>
<p><b>NOTE:</b> For the moment, I have not implemented support for custom mappings.</p>
<p>The virtual joystick can be enabled or disabled with the following function:</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;// Enable the virtual joystick</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;QJoysticks::getInstance()-&gt;setVirtualJoystickEnabled (true);</div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;// Disable the virtual joystick</div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;QJoysticks::getInstance()-&gt;setVirtualJoystickEnabled (false);</div></div><!-- fragment --><h3>3. How are joystick events reported?</h3>
<p>The QJosyticks library reports joystick events with the following signals:</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;// Only for C++ applications</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;void POVEvent (const QJoystickPOVEvent&amp; event);</div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;void axisEvent (const QJoystickAxisEvent&amp; event);</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;void buttonEvent (const QJoystickButtonEvent&amp; event);</div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;// For C++ applications &amp; QML applications</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;void povChanged (const int js, const int pov, const int angle);</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;void axisChanged (const int js, const int axis, const double value);</div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;void buttonChanged (const int js, const int button, const bool pressed);</div></div><!-- fragment --><h3>3. How are axis values reported?</h3>
<p>This library reports an axis value with a range from -1.0 to 1.0 (with 0.0 being neutral). You can customize the axis range of the virtual joystick with the following function:</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;QJoysticks::getInstance()-&gt;setVirtualJoystickAxisRange (0.8);</div></div><!-- fragment --><p>You cannot customize the axis range of the SDL joysticks.</p>
<h2>License</h2>
<p>This project is released under the MIT license. </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>
